package controller;

import begin.MainView;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import service.MainService;
import tools.UtilMessage;

/**
 * @Author 王志康
 * @Date 2021/9/5 16:39
 * @Version 1.0.0
 */
public class LoginController {
    @FXML
    private TextField inputNumber;

    @FXML
    private TextField inputPassword;

    /**
     * 监听用户登录页面点击登录事件
     *
     * @param mouseEvent 鼠标事件
     */
    @FXML
    public void loginClicked(MouseEvent mouseEvent) {
        String number = inputNumber.getText();
        String password = inputPassword.getText();
        if (MainService.login(number, password)) {
            //关闭登录页面
            Stage stage = (Stage) inputNumber.getScene().getWindow();
            stage.close();
        }
        inputPassword.clear();
    }

    /**
     * 跳转至用户登录页面
     *
     * @param mouseEvent 鼠标事件
     */
    @FXML
    public void registerClicked(MouseEvent mouseEvent) {
        MainView.gotoRegisterView();
    }
}
